package com.wn34.goods.controller;

import com.github.pagehelper.PageInfo;
import com.wn34.goods.entity.User;
import com.wn34.goods.service.OrderService;
import com.wn34.goods.vo.OrdersVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
@RequestMapping("order")
public class OrderController {
    @Autowired
    OrderService orderService;

    @RequestMapping("/orderList")
    public String orderList(HttpServletRequest req,
                            @RequestParam(value = "now", defaultValue = "1") Integer now,
                            @RequestParam(value = "size", defaultValue = "4") Integer size,
                            Map map) {
        User user = (User) req.getSession().getAttribute("loginUser");
        now = now == 0 ? 1 : now;
        PageInfo<OrdersVo> pageInfo = orderService.pageInfo(now, size, user.getUserid());
        map.put("pageInfo", pageInfo);
        return "forward:/orders.html";
    }

    @RequestMapping("/removeOrder")
    @ResponseBody
    public String removeOrder(Integer orderId) {
        return orderService.removeOrder(orderId) + "";
    }
}
